<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Laporan extends Admin_My_Controller {

    function __construct() {
        parent::__construct();

        /* Standard Libraries of codeigniter are required */
        $this->load->database();
        $this->load->helper('url');
        /* ------------------ */        
    }
    
    function laba_rugi(){
        $this->load->model('laporan/laba_rugi');
        $data = array();
        $data['date_picker'] = new jDatePicker();
        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-")."01";
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
       
        $where = "and date(k.tanggal_dp) between  '".$data['srcPeriodStart']."' and '".$data['srcPeriodEnd']."'";
        $whereOperasional = "and date(k.tanggal_ko) between  '".$data['srcPeriodStart']."' and '".$data['srcPeriodEnd']."'";
       
        $data["total_penjualan"] = $this->laba_rugi->getTotalPenjualan($where);
        $data["beban_penjualan"] = $this->laba_rugi->getBebanPokok($where);
        $data["diskon"] = $this->laba_rugi->getDiskonPenjualan($where);
        $data["operasional"] = $this->laba_rugi->getOperasional($whereOperasional);        

        if ($this->input->get_post('export')) {
            $data['export'] = true;
            $this->loadMenuExport('/laporan/laba_rugi',$data);
        } else {
            $this->loadMenu('/laporan/laba_rugi',$data);
        }
    }
    
    function belanja_supplier(){
        $this->load->model('laporan/belanja');
        $data = array();
        $data['date_picker'] = new jDatePicker();
        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-")."01";
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
       
        $where = " where date(di.tanggal_invoice) between  '".$data['srcPeriodStart']."' and '".$data['srcPeriodEnd']."'";        
       
        $data["belanja_supplier"] = $this->belanja->getBelanjaSupplier($where);
        if ($this->input->get_post('export')) {
            $data['export'] = true;
            $this->loadMenuExport('/laporan/belanja_supplier',$data);
        } else {
            $this->loadMenu('/laporan/belanja_supplier',$data);
        }
    }
    
    function penjualan(){
        $this->load->model('laporan/belanja');
        $data = array();
        $data['date_picker'] = new jDatePicker();
        $data['srcPeriodStart'] = $this->input->get_post('srcPeriodStart') != "" ? $this->input->get_post('srcPeriodStart') : date("Y-m-")."01";
        $data['srcPeriodEnd'] = $this->input->get_post('srcPeriodEnd') != "" ? $this->input->get_post('srcPeriodEnd') : date("Y-m-d");
       
        $where = " where date(di.tanggal_invoice) between  '".$data['srcPeriodStart']."' and '".$data['srcPeriodEnd']."'";        
       
        $data["belanja_supplier"] = $this->belanja->getBelanjaCustomer($where);
        if ($this->input->get_post('export')) {
            $data['export'] = true;
            $this->loadMenuExport('/laporan/belanja_customer',$data);
        } else {
            $this->loadMenu('/laporan/belanja_customer',$data);
        }
    }
}



/* End of file main.php */
/* Location: ./application/controllers/main.php */